package com.summer.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.summer.entity.UserInfo;
import com.summer.mapper.UserInfoMapper;
import com.summer.service.IUserInfoService;
import com.summer.util.CallBackResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Desc:
 * Created by tl on 2018/12/20
 */
@RestController
@RequestMapping("/v1.0/api/userInfo")
public class UserInfoController {
    private static Logger log = LoggerFactory.getLogger(UserInfoController.class);
    @Resource
    private IUserInfoService userInfoService;
    @Resource
    private UserInfoMapper userInfoMapper;

    /**
     * 客户列表
     *
     * @param jsonData
     * @return
     */
    @PostMapping("/queryWithBorrow")
    public String queryWithBorrow(@RequestBody String jsonData) {
        Map<String, Object> params = JSONObject.parseObject(jsonData);
        log.info("UserInfoController query params=" + params.toString());
        PageHelper.startPage(params);
        PageInfo<UserInfo> pageInfo = userInfoService.queryWithBorrow(params);
        return CallBackResult.returnJson(pageInfo);
    }

    /**
     * 未认证列表
     *
     * @param jsonData
     * @return
     */
    @PostMapping("/queryUnauthentic")
    public String queryUnauthentic(@RequestBody String jsonData) {
        Map<String, Object> params = JSONObject.parseObject(jsonData);
        log.info("UserInfoController queryUnauthentic params=" + params.toString());
        PageHelper.startPage(params);
        Object authenticObj = params.get("authentic");
        if (null == authenticObj) {
            //未认证
            params.put("unauthentic", "true");
        }
        List<UserInfo> list = userInfoMapper.findParams(params);
        return CallBackResult.returnJson(new PageInfo<>(list));
    }

}